package pluginUtils;

/** Indra's Pearls project 3.7 page 95
 * The Geometry of Complex Numbers Hans Schwerdtfeger page 4 
 * @author decomite
 *
 */ 
public class GeneralizedCircle {
	protected double gca,gcd; 
	protected Complexe gcb,gcc; 
	
	/**
	 * @param a
	 * @param d
	 * @param b
	 * @param c
	 */
	public GeneralizedCircle(double a, Complexe b, Complexe c,double d) {
		super();
		this.gca = a;
		this.gcd = d;
		this.gcb = b;
		this.gcc = c;
	}
	
	public double getRadius(){
		return Math.sqrt(gcb.squareNorm()/(gca*gca)-gcd/gca);
	}
	
	public double determinant(){
		return gca*gcd-gcb.squareNorm(); 
	}
	
	public String toString(){
		String s=gca+","+gcb+","+gcc+","+gcd+"\n"; 
		if(gca!=0){
			if(this.determinant()<0){
				s+="Real Circle \n";
				double radius=Math.sqrt(gcb.squareNorm()/(gca*gca)-gcd/gca);
				Complexe center=Complexe.mulbyDouble(gcc,-1/gca); 
				s+="Radius :"+radius+"\n"+"Center :"+center; 
			}
			if(this.determinant()==0){
				s+="Point Circle\n";
				Complexe center=Complexe.mulbyDouble(gcc,-1/gca); 
				s+="Center :"+center; 
			}
			if(this.determinant()>0){
				s+="Imaginary Circle\n";
			}
		}
	if(gca==0){
		s+="Line\n";
		if(gcb.getIm()==0) s+="Vertical \n"; 
			
	}
	s+=" Radius :"+this.getRadius(); 
	return s;
	}
	
	public GeneralizedCircle(Circle c){
		Complexe gamma=c.getCenter(); 
		double radius=c.getRadius();
		this.gca=1; 
		this.gcc=Complexe.mulbyDouble(gamma,-1); 
		this.gcb=this.gcc.conjugate(); 
		this.gcd=gamma.squareNorm()-radius*radius;
	}
	
	public static void main(String[] args) {
		Circle c1=new Circle(Complexe.createComplexeFromRI(3,4),5); 
		GeneralizedCircle gc=new GeneralizedCircle(c1); 
		System.out.println(gc);
		
		// T=kz
		Complexe a=Complexe.createComplexeFromRI(1,0);
		Complexe b=Complexe.createComplexeFromRI(0,0); 
		Complexe c=Complexe.createComplexeFromRI(0,0);
		Complexe d=Complexe.createComplexeFromRI(0,0); 
		MobiusTransform T=new MobiusTransform(a,b,c,d); 
		
		GeneralizedCircle imgc=T.generalizedCircleImage(gc); 
		System.out.println(imgc); 
		
		
	}

	/**
	 * @return the gca
	 */
	public double getGca() {
		return gca;
	}

	/**
	 * @return the gcd
	 */
	public double getGcd() {
		return gcd;
	}

	/**
	 * @return the gcb
	 */
	public Complexe getGcb() {
		return gcb;
	}

	/**
	 * @return the gcc
	 */
	public Complexe getGcc() {
		return gcc;
	}

	
}











